/**
 * @author: wq
 * @Date: 2017/6/10
 * @Time: 15:43
 * <p>
 * Description:
 *          ***
 */

import axios from 'axios';
import {API_NEW_VERSION} from '../api';

var qs = require('qs');

const FREIGHT_CONTRACTS = API_NEW_VERSION + 'freight/contracts';
const FREIGHT_CONTRACTS_CHANGE_STATUS = API_NEW_VERSION + 'freight/contracts/change_status';
const FREIGHT_CONTRACT = API_NEW_VERSION + 'freight/contract/';
const FREIGHT_CONTRACT_LINES = API_NEW_VERSION + 'freight/contract/lines';
const FREIGHT_CONTRACT_LINE_DETAILS = API_NEW_VERSION + 'freight/contract/line/details';
const FREIGHT_CONTRACT_LINE_DETAIL = API_NEW_VERSION + 'freight/contract/line/detail/';

/**
 * 查询运价合同列表
 * @param params
 * @returns {AxiosPromise}
 */
export const searchFreightContracts = params => {
  return axios.get(FREIGHT_CONTRACTS, {params: params});
};

/**
 * 保存运价文件
 * @param params
 * @returns {AxiosPromise}
 */
export const saveFreightContract = params => {
  return axios.post(FREIGHT_CONTRACTS, params);
};

/**
 * 根据id修改合同运价的状态
 * @param id
 * @param status
 * @returns {AxiosPromise}
 */
export const changeStatus = (id, status) => {
  return axios.post(FREIGHT_CONTRACTS_CHANGE_STATUS, qs.stringify({id: id, status: status}));
};

/**
 * 根据id删除合同运价的状态
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteFreightContract = id => {
  return axios.delete(FREIGHT_CONTRACT + id);
};

/**
 * 根据id查询合同运价
 * @param id
 * @returns {AxiosPromise}
 */
export const getFreightContract = id => {
  return axios.get(FREIGHT_CONTRACT + id);
};

/**
 * 保存运价线路合同文件
 * @param params
 * @returns {AxiosPromise}
 */
export const saveFreightContractLine = params => {
  return axios.post(FREIGHT_CONTRACT_LINES, params);
};

/**
 * 查询运价线路合同文件列表
 * @param params
 * @returns {AxiosPromise}
 */
export const searchFreightContractLines = params => {
  return axios.get(FREIGHT_CONTRACT_LINES, {params: params});
};

/**
 * 根据id删除合同运价线路
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteFreightContractLine = id => {
  return axios.delete(FREIGHT_CONTRACT_LINES + '/' + id);
};

/**
 * 新增合同运价线路详情
 * @param params
 * @returns {AxiosPromise}
 */
export const saveFreightContractLineDetail = params => {
  return axios.post(FREIGHT_CONTRACT_LINE_DETAILS, params);
};

/**
 * 查询运价线路详情合同文件列表
 * @param params
 * @returns {AxiosPromise}
 */
export const searchFreightContractLineDetails = params => {
  return axios.get(FREIGHT_CONTRACT_LINE_DETAILS, {params: params});
};

/**
 *根据ids，批量删除运价线路详情合同文件
 * @param params
 * @returns {AxiosPromise}
 */
export const deleteFreightContractLineDetail = id => {
  return axios.delete(FREIGHT_CONTRACT_LINE_DETAIL + id);
};
